<?php

namespace App\Supports\Payment\Methods\Wxpay;

use Illuminate\Support\Facades\Log;
use App\Supports\Payment\Methods\Method;
use App\Supports\Payment\Contracts\MethodCallback;

class CallbackWxpay extends Method implements MethodCallback
{
	public function markAsPaid($order = null, $data = null) {}

	public function validate($data = null) {}

	protected function paidCallback($data)
	{
		$tag = $this->getPaidTag($data['out_trade_no']);

		if ($tag == 'order') {
			return cashier('wxpay')->callbackOrderPay($data);
		}
		if ($tag == 'vip') {
			return cashier('wxpay')->callbackVipPay($data);
		}

		return 'fail';
	}

	protected function refundCallback($data)
	{
		$tag = $this->getPaidTag($data['out_trade_no']);

		if ($tag == 'order') {
			return cashier('wxpay')->callbackOrderRefund($data);
		}
		if ($tag == 'vip') {
			return cashier('wxpay')->callbackVipRefund($data);
		}
		return 'fail';
	}

	public function callback($data = null)
	{
		$result = $this->channel->verify();

		if ($result['refund_fee'] > 0) {
			return $this->refundCallback($result);
		}
		return $this->paidCallback($result);
	}
}
